<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>我的购物车-小米商城</title>
        <link rel="stylesheet" type="text/css" href="/style/home/css/style.css">
        <script src="/js/jquery-1.8.3.min.js"></script>
        <style>
            table{
                width:1200px;
            }
            td{
                text-align: center;
                width:14%;
            }
        </style>
    </head>
    <body>
        <!-- start header -->
        <!--end header -->

        <!-- start banner_x -->
        <div class="banner_x center">
            <a href="/home/index" target="_blank"><div class="logo fl"></div></a>

            <div class="wdgwc fl ml40">我的购物车</div>
            <div class="wxts fl ml20">温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</div>
            <div class="dlzc fr">
                @if(Session::get('home_user'))
                欢迎您！{{Session::get('home_user')}}
                @else
                <ul>
                    <li><a href="/home/login" target="_blank">登录</a></li>
                    <li>|</li>
                    <li><a href="/home/register" target="_blank">注册</a></li>	
                </ul>
                @endif

            </div>
            <div class="clear"></div>
        </div>
        <div class="xiantiao"></div>
        <div class="gwcxqbj">
            <div class="gwcxd center">
                <table> 
                    <tr>
                        <td><input type="checkbox" value="quanxuan" class="quanxuan" />全选</td>
                        <td>商品名称</td>
                        <td>商品图片</td>
                        <td>单价</td>
                        <td>数量</td>
                        <td>小计</td>
                        <td>操作</td> 
                    </tr>
                    @foreach($data as $v) 
                    <tr>
                        <td><input type="checkbox" onclick="tot();" value="{{$v->id}}" class="quanxuan" /></td>
                        <td>{{$v->title}}</td>
                        <td><img src="{{$v->img}}" width="160" height="110" /></td>
                        <td class="price">{{$v->price}}.00元</td>
                        <td><input class="number" style="width:40px;height:25px;text-align: center;" type="number" value="{{$v->num}}" step="1" min="1" ></td>
                        <td class="count">{{$v->price*$v->num}}<span>.00元</span></td>
                        <td></td>    
                    </tr> 
                    @endforeach
                </table>   
            </div>
            <div class="jiesuandan mt20 center">
                <div class="tishi fl ml20">
                    <ul>
                        <li><a href="./liebiao.html">继续购物</a></li>
                        <li>|</li>
                        <li>共<span>{{$cot}}</span>件商品，已选择<span class="cnt"></span>件</li>
                        <div class="clear"></div>
                    </ul>
                </div>
                <div class="jiesuan fr">
                    <div class="jiesuanjiage fl">合计（不含运费）：<span class="total"></span></div>
                    <div class="jsanniu fr"><input class="jsan" onclick="balance();"  type="submit" name="jiesuan"  value="去结算"/></div>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>

        </div> 
        <script>
            var total = 0; 
            $(".cnt").text($("input[type='checkbox']:checked").length);
            $(".count").each(function () {
                total += parseInt($(this).text().split(".")[0]);
            })
            $(".total").text(total + ".00元") 
            $(".number").change(function () {
                var total = 0;
                var num = $(this).val();
                if(num<=0){ 
                    alert("请填写正确的数量");
                    $(this).val("1");
                    return false;
                }
                price = $(this).parents().children(".price").text();
                var price = price.split(".")[0];
                var count = num * price;
                $(this).parents().siblings(".count").text(count + ".00元");
                var id = $(this).parents().siblings().children(".quanxuan").val();
                $.post("/home/ChangeNum/" + id, {"num": num, "_token": "{{csrf_token()}}", "_method": "get"}, function (data) {
                });
                $(".count").each(function () {
                    total += parseInt($(this).text().split(".")[0]);
                })
                $(".total").text(total + ".00元")
            }); 
            function tot() {
                cnt = $("input[type='checkbox']:checked").length;
                $(".cnt").text(cnt);
            }
            function balance(){
                var ids="";
                $("input[type='checkbox']:checked").each(function () {
                   ids+=$(this).val()+",";     
                });
                $.post('/home/orders/'+ids,{"_token":"{{csrf_token()}}","_method":"get"},function(data){
                     window.location.href='/home/orders/'+ids;
                })
                
            }
        </script>
        <!-- footer -->
        @include('foot') 
